/**
 * @author abid.hussain
 */
exports.GAConnectResponse = GAServerResponseCommonModel.subclass({
	classname : 'GAConnectResponse',
	initialize : function($super,serverResponse){
		$super(serverResponse);
		this._firstGameState = null ;
		this._serverResponse = serverResponse;
		this._currencyModelArray = []; 
		this._storesModelArray = []; 
		this._userMessageModel = null;
		this._count_threshold=0;
		this._dazzle_server=null;
		this._logging_type=0;
		this._time_threshold=0;
		this._log_transaction= null;
		this._log_event= null;
		this._log_offer= null;
		this._friendAdded = null;
		this._promotions = null;
		this._neighborActions = null;
		
		this._serverXp = null;//Zulu Custom Code
		//console.log("zaki::::: server response is "+this._serverResponse);
	},
	parseConnectResponse : function(){
		if(this._serverResponse != 'undefined' && this._serverResponse != null){
			var social = this._serverResponse.SocialAction;
			if(social != 'undefined' && social != null){
				this._friendAdded = social.friendAdded;
			}
			this._friendAdded = (this._friendAdded != null && this._friendAdded.toLowerCase() == "True".toLowerCase()) ? true : false;
			this._parseStoreVersions();
			this._parseCurrencies();
			this._populateUserMessageModel();
			this._populatePromotions();
			this._populateDazzleInfo();
			this._parseNeighborActions();
		}
	},
	
	_parseNeighborActions: function()
	{
		var neighborActions = this._serverResponse.neighboractions;
		this._neighborActions = neighborActions;
	},
	
	_parseStoreVersions : function(){
		var storeVersions = this._serverResponse.storeItemVersion;
		//console.log("zaki::::: storeVersions1 "+JSON.stringify(this._serverResponse));
		
		if(storeVersions != 'undefined' && storeVersions != null){
			//console.log("zaki::::: storeVersions.store "+JSON.stringify(storeVersions.store));
			var stores = storeVersions.store;
			if(stores != 'undefined' && stores != null){
				var totalStores = stores.length;
				//console.log("zaki::::: _parseStoreVersions totalStores"+totalStores);
				for(var i=0; i<totalStores; i++){
					var storeVersionModel = new GAStoreVersionModel(stores[i]);
					this._storesModelArray.push(storeVersionModel);
				}
			}
		}
	},
	_parseCurrencies : function(){
		var currenciesObjet = this._serverResponse.currencies;
		if(currenciesObjet!='undefined' && currenciesObjet != null){
			var currencies = currenciesObjet.currency;
			if(currencies != 'undefined' && currencies != null){
				var totalCurrency = currencies.length;
				for(var i=0; i<totalCurrency; i++){
					var currencyModel = new GACurrenciesModel(currencies[i]);
					this._currencyModelArray.push(currencyModel);
				}
			}
		}
	},
	_populateUserMessageModel : function (){
		var userMessageObject = this._serverResponse.UserMessage;
		if(userMessageObject != 'undefined' && userMessageObject != null){
			this._userMessageModel = new GAUserMessageModel();
			this._userMessageModel.setCategory(userMessageObject['@category']);
			this._userMessageModel.setItemId(userMessageObject['@itemId']);
			this._userMessageModel.setStoreName(userMessageObject['@store']);
			this._userMessageModel.setMessage(userMessageObject['#text']);
		}
	},
	_populatePromotions: function(){
		var promotionsObject = this._serverResponse.promotions;
		if(promotionsObject != 'undefined' && promotionsObject != null){
			this._promotions = new GAPromotionsModel();
			this._promotions.parsePromotions(promotionsObject);
		}
	},
	_populateDazzleInfo : function (){
		var dazzleObject = this._serverResponse.dazzle;
		if(dazzleObject!='undefined' && dazzleObject != null){
			this._count_threshold = dazzleObject['@count_threshold'];
			this._dazzle_server = dazzleObject['@dazzle_server'];
			this._log_event = dazzleObject['@log_event'];
			this._log_offer = dazzleObject['@log_offer'];
			this._log_transaction = dazzleObject['@log_transaction'];
			this._log_event = (this._log_event != null && this._log_event == "1") ? true : false;
			this._log_offer = (this._log_offer != null && this._log_offer == "1") ? true : false;
			this._log_transaction = (this._log_transaction != null && this._log_transaction == "1") ? true : false;
			this._logging_type = dazzleObject['@logging_type'];
			this._time_threshold = dazzleObject['@time_threshold'];
		}
	},
	getNeighborActions: function()
	{
		return this._neighborActions;
	},
	getFriendAdded: function(){
		return this._friendAdded;
	},
	getPromotions: function(){
		return this._promotions;
	},
	getUserMessageModel: function(){
		return this._userMessageModel;
	},
	getCurrencyModel : function(){
		return this._currencyModelArray;
	},	
	getStoresModel : function(){
		return this._storesModelArray;
	},
	getCountThreshold : function (){
		return this._count_threshold;
	},
	getTimeThreshold : function (){
		return this._time_threshold;
	},
	getDazzleServer : function (){
		return this._dazzle_server;
	},
	getLogEvent : function (){
		return this._log_event;
	},
	getLogOffer : function (){
		return this._log_offer;
	},
	getLogTransaction : function (){
		return this._log_transaction;
	},
	getLoggingType : function (){
		return this._logging_type;
	},
	getStoreNames : function (){
		var names = [];
		var length = this._storesModelArray.length;
		for(var i = 0; i < length ; i ++ ){
			names.push(this._storesModelArray[i].getStoreName());
		}
		return names;
	},
	getStoreVisibleIds: function() {
		var visibleIds = [];
		var length = this._storesModelArray.length;
		//console.log("zaki::::: store models length is "+length);
		for(var i = 0; i < length ; i ++ ){
			visibleIds.push(this._storesModelArray[i].getVisibleId());
		}
		return visibleIds;		
	},
	getStoreVersion : function(visibleId){
		var length = this._storesModelArray.length;
		for(var i = length-1 ; i >= 0 ; i-- ){
			if(visibleId == this._storesModelArray[i].getVisibleId()){
				return this._storesModelArray[i].getStoreVersion();
			}
		}
	},
	getStoreId : function(visibleId){
		var length = this._storesModelArray.length;
		for(var i = length; i -- ; ){
			if(visibleId == this._storesModelArray[i].getVisibleId()){
				return this._storesModelArray[i].getStoreId();
			}
		}
	},
	destroy : function($super){
		var modelSize = this._currencyModelArray.length;
		for( var count = 0; count < modelSize ; count ++)
		{
			if(this._currencyModelArray[count] != null){
				this._currencyModelArray[count].destroy();
				this._currencyModelArray[count] = null;
			}
		}
		this._currencyModelArray = null;
		modelSize = this._storesModelArray.length;
		for( var count = 0 ; count < modelSize ; count ++)
		{
			if(this._storesModelArray[count] != null){
				this._storesModelArray[count].destroy();
				this._storesModelArray[count] = null;
			}
		}
		this._storesModelArray = null;
		this._serverResponse = null;
		if(this._promotions != null){
			this._promotions.destroy();
			this._promotions = null;
		}
		this._friendAdded = null;
		this._signatur =null;
		this._firstGameState = null ; 
		this._userMessageModel = null;
		this._count_threshold= null;
		this._dazzle_server= null;
		this._logging_type= null;
		this._time_threshold= null;
		this._log_transaction= null;
		this._log_event= null;
		this._log_offer= null;
		this._neighborActions = null
		$super();
	}
	
}); 